package com.jxauaia.contest.service.impl;

import com.jxauaia.contest.AI.OkHttpAIClient;
import com.jxauaia.contest.mapper.ContestMapper;
import com.jxauaia.contest.service.AIService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AIServiceImpl implements AIService {

    private static final Logger logger = LoggerFactory.getLogger(AIServiceImpl.class);

    private final OkHttpAIClient okHttpAIClient;
    private final ContestMapper contestMapper;

    @Autowired
    public AIServiceImpl(OkHttpAIClient okHttpAIClient, ContestMapper contestMapper) {
        this.okHttpAIClient = okHttpAIClient;
        this.contestMapper = contestMapper;
    }

    @Override
    public String processQuestion(Integer userId, String question) {
        logger.debug("开始处理用户问题: {}", question);

        // 直接调用AI服务，不添加比赛信息上下文
        String userId_str = userId != null ? userId.toString() : "anonymous";
        return okHttpAIClient.askQuestion(question, userId_str);
    }

    // 可以添加一个新方法，专门用于简单的AI调用测试
    public String testAI(String question) {
        logger.info("测试AI调用: {}", question);
        return okHttpAIClient.askQuestion(question, "test_user");
    }
}